<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>fc</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_001_014_662">&nbsp;</a>NAME</h4><blockquote>
fc - process the command history list
</blockquote><h4><a name = "tag_001_014_663">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

fc <b>[</b>-r<b>][</b>-e <i>editor</i><b>] [</b><i>first</i><b>[</b><i>last</i><b>]]</b>

fc -l<b>[</b>-nr<b>] [</b><i>first</i><b>[</b><i>last</i><b>]]</b>

fc -s<b>[</b><i>old</i>=<i>new</i><b>][</b><i>first</i><b>]</b>
</code>
</pre>
</blockquote><h4><a name = "tag_001_014_664">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>fc</i>
utility lists or edits and reexecutes,
commands previously entered to an interactive
<i><a href="sh.html">sh</a></i>.
<p>
The command history list references commands by number.
The first number in the list is selected arbitrarily.
The relationship of a number to its command
will not change except when
the user logs in and no
other process is accessing the list, at which time the
system may reset the numbering to start
the oldest retained command at another number (usually 1).
When the number reaches an implementation-dependent upper limit,
which will be no smaller than the value in
<i>HISTSIZE</i>
or 32767 (whichever is greater),
the shell may wrap the numbers, starting the
next command with a lower number (usually 1).
However, despite this optional wrapping of numbers,
<i>fc</i>
will maintain the time-ordering sequence of the commands.
For example, if four commands in sequence are given the numbers
32766, 32767, 1 (wrapped),
and 2 as they are executed, command 32767
is considered the command previous to 1,
even though its number is higher.
<p>
When commands are edited (when the
<b>-l</b>
option is not specified), the resulting lines will be
entered at the end of the history list and then reexecuted by
<i><a href="sh.html">sh</a></i>.
The
<i>fc</i>
command that caused the editing will not be entered into the history list.
If the editor returns a non-zero exit status,
this will suppress the entry into the history list
and the command reexecution.
Any command-line variable assignments or redirection operators
used with
<i>fc</i>
will affect both the
<i>fc</i>
command itself as well as the command that results, for example:
<pre>
<code>
fc -s -- -1 2&gt;/dev/null
</code>
</pre>
reinvokes the previous command, suppressing standard error
for both
<i>fc</i>
and the previous command.
</blockquote><h4><a name = "tag_001_014_665">&nbsp;</a>OPTIONS</h4><blockquote>
The
<i>fc</i>
utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b>&nbsp;</a> .
<p>
The following options are supported:
<dl compact>

<dt><b>-e&nbsp;</b><i>editor</i>
<dd>
Use the editor named by
<i>editor</i>
to edit the commands.
The
<i>editor</i>
string is a utility name, subject to search via the
<i>PATH</i>
variable (see
the <b>XBD</b> specification, <a href="../xbd/envvar.html"><b>Environment Variables</b>&nbsp;</a> ).
The value in the
<i>FCEDIT</i>
variable is used as a default when
<b>-e</b>
is not specified.
If
<i>FCEDIT</i>
is null or unset,
<i><a href="ed.html">ed</a></i>
will be used as the editor.

<dt><b>-l</b>
<dd>(The letter ell.)
List the commands rather than invoking an editor on them.
The commands will be written
in the sequence indicated by the
<i>first</i>
and
<i>last</i>
operands, as affected by
<b>-r</b>,
with each command preceded by the command number.

<dt><b>-n</b>
<dd>Suppress command numbers when listing with
<b>-l</b>.

<dt><b>-r</b>
<dd>Reverse the order of the commands listed (with
<b>-l</b>)
or edited (with neither
<b>-l</b>
nor
<b>-s</b>).

<dt><b>-s</b>
<dd>Reexecute the command without invoking an editor.

</dl>
</blockquote><h4><a name = "tag_001_014_666">&nbsp;</a>OPERANDS</h4><blockquote>
The following operands are supported:
<dl compact>

<dt><i>first</i><dd>
<dt><i>last</i><dd>Select the commands to list or edit.
The number of previous commands that can be accessed
is determined by the value of the
<i>HISTSIZE</i>
variable.
The value of
<i>first</i>
or
<i>last</i>
or both will be one of the following:
<dl compact>

<dt><b>[+]</b><i>number</i><dd>
A positive number representing a command number;
command numbers can be displayed with the
<b>-l</b>
option.

<dt><b>-</b><i>number</i><dd>
A negative decimal number representing the command that was executed
<i>number</i>
of commands previously.
For example, -1 is the immediately previous command.

<dt><i>string</i><dd>A string indicating the most recently entered command
that begins with that string.
If the
<i>old=new</i>
operand is not also specified with
<b>-s</b>,
the string form of the
<i>first</i>
operand cannot contain an embedded equal sign.

</dl>
<p>
When the synopsis form with
<b>-s</b>
is used:
<ul>
<p>
<li>
If
<i>first</i>
is omitted, the previous command will be used.
<p>
</ul>
<p>
For the synopsis forms without
<b>-s</b>:
<ul>
<p>
<li>
If
<i>last</i>
is omitted,
<i>last</i>
defaults to
the previous command when
<b>-l</b>
is specified; otherwise, it defaults to
<i>first</i>.
<p>
<li>
If
<i>first</i>
and
<i>last</i>
are both omitted, the previous 16 commands will be listed
or the previous single command will be edited (based on the
<b>-l</b>
option).
<p>
<li>
If
<i>first</i>
and
<i>last</i>
are both present,
all of the commands from
<i>first</i>
to
<i>last</i>
will be edited (without
<b>-l</b>)
or listed (with
<b>-l</b>).
Editing multiple commands will be accomplished
by presenting to the editor all of the commands at one time,
each command starting on a new line.
If
<i>first</i>
represents a newer command than
<i>last</i>,
the commands will be listed or edited
in reverse sequence, equivalent to using
<b>-r</b>.
For example, the following commands
on the first line are equivalent
to the corresponding commands on the second:
<pre>
<code>
fc -r 10 20    fc    30 40
fc    20 10    fc -r 40 30
</code>
</pre>
<p>
<li>
When a range of commands is used, it will not be an
error to specify
<i>first</i>
or
<i>last</i>
values that are not in the history list;
<i>fc</i>
will substitute the value representing the
oldest or newest command in the list, as appropriate.
For example, if there are only ten commands in the history list,
numbered 1 to 10:
<pre>
<code>
fc -l
fc 1 99
</code>
</pre>
will list and edit, respectively, all ten commands.
<p>
</ul>
<p>
<dt><i>old=new</i><dd>
Replace the first occurrence of string
<i>old</i>
in the commands to be
reexecuted by the string
<i>new</i>.
<p>
</dl>
</blockquote><h4><a name = "tag_001_014_667">&nbsp;</a>STDIN</h4><blockquote>
Not used.
</blockquote><h4><a name = "tag_001_014_668">&nbsp;</a>INPUT FILES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_669">&nbsp;</a>ENVIRONMENT VARIABLES</h4><blockquote>
The following environment variables affect the execution of
<i>fc</i>:
<dl compact>

<dt><i>FCEDIT</i><dd>
This variable, when expanded by the shell,
determines the default value for the
<b>-e</b>&nbsp;<i>editor</i>
option's
<i>editor</i>
option-argument.
If
<i>FCEDIT</i>
is null or unset,
<i><a href="ed.html">ed</a></i>
will be used as the editor.

<dt><i>HISTFILE</i><dd>
Determine a pathname naming a command history file.
If the
<i>HISTFILE</i>
variable is not set, the
shell may attempt to access or create a file
<b>.sh_history</b>
in the user's home directory.
If the shell cannot
obtain both read and write access to,
or create, the history file,
it will use an unspecified mechanism that allows the history
to operate properly.
(References to history &quot;file&quot; in this section
are understood to mean this unspecified mechanism
in such cases.)
An implementation may choose to access this variable only when
initialising the history file;
this initialisation will occur when
<i>fc</i>
or
<i><a href="sh.html">sh</a></i>
first attempt to retrieve entries from,
or add entries to, the file, as the result of
commands issued by the user, the file named by the
<i>ENV</i>
variable, or implementation-dependent system startup files.
(The initialisation process for the history file
can be dependent on the system startup files, in that
they may contain commands that will effectively
preempt the user's settings of
<i>HISTFILE</i>
and
<i>HISTSIZE .
</i>For example, function definition commands are recorded
in the history file, unless the
<i>set</i>
<b>-o</b>
<b>nolog</b>
option is set.
If the system administrator includes function definitions
in some system startup file called before the
<i>ENV</i>
file, the history file will be initialised before
the user gets a chance to influence its characteristics.)
In some historical shells, the history file is initialised
just after the
<i>ENV</i>
file has been processed.
Therefore, it is implementation-dependent whether changes made to
<i>HISTFILE</i>
after the history file has been initialised are effective.
Implementations may choose to disable the history list
mechanism for users with appropriate privileges who do not set
<i>HISTFILE ;
</i>the specific circumstances under which this will occur are
implementation-dependent.
If more than one instance of the shell is using the same history
file, it is unspecified how updates to the history file from
those shells interact.
As entries are deleted from the history file,
they will be deleted oldest first.
It is unspecified when history file entries are
physically removed from the history file.

<dt><i>HISTSIZE</i><dd>
Determine a decimal number representing
the limit to the number of previous commands that are accessible.
If this variable is unset,
an unspecified default greater than or equal to 128 will be used.
The maximum number of commands in the history list is unspecified,
but will be at least 128.
An implementation may choose to access this variable only when
initialising the history file,
as described under
<i>HISTFILE .
</i>Therefore, it is unspecified whether changes made to
<i>HISTSIZE</i>
after the history file has been initialised are effective.

<dt><i>LANG</i><dd>Provide a default value for the internationalisation variables
that are unset or null.
If
<i>LANG</i>
is unset or null, the corresponding value from the
implementation-dependent default locale will be used.
If any of the internationalisation variables contains an invalid setting, the
utility will behave as if none of the variables had been defined.

<dt><i>LC_ALL</i><dd>
If set to a non-empty string value,
override the values of all the other internationalisation variables.

<dt><i>LC_CTYPE</i><dd>
Determine the
locale for the interpretation of sequences of bytes of text data as
characters (for example, single- as opposed to multi-byte characters
in arguments and input files).

<dt><i>LC_MESSAGES</i><dd>
Determine the locale that should be used to affect
the format and contents of diagnostic
messages written to standard error.

<dt><i>NLSPATH</i><dd>
Determine the location of message catalogues
for the processing of
<i>LC_MESSAGES .
</i>
</dl>
</blockquote><h4><a name = "tag_001_014_670">&nbsp;</a>ASYNCHRONOUS EVENTS</h4><blockquote>
Default.
</blockquote><h4><a name = "tag_001_014_671">&nbsp;</a>STDOUT</h4><blockquote>
When the
<b>-l</b>
option is used to list commands, the format of each command in
the list is as follows:
<p><code>
<tt>"%d\t%s\n"</tt>, &lt;<i>line number</i>&gt;,
&lt;<i>command</i>&gt;
</code>
<p>
If both the
<b>-l</b>
and
<b>-n</b>
options are specified, the format of each command is:
<p><code>
<tt>"\t%s\n"</tt>, &lt;<i>command</i>&gt;
</code>
<p>
If the
&lt;<i>command</i>&gt;
consists of more than one line, the lines after the first are
displayed as:
<p><code>
<tt>"\t%s\n"</tt>, &lt;<i>continued-command</i>&gt;
</code>
</blockquote><h4><a name = "tag_001_014_672">&nbsp;</a>STDERR</h4><blockquote>
Used only for diagnostic messages.
</blockquote><h4><a name = "tag_001_014_673">&nbsp;</a>OUTPUT FILES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_674">&nbsp;</a>EXTENDED DESCRIPTION</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_675">&nbsp;</a>EXIT STATUS</h4><blockquote>
The following exit values are returned:
<dl compact>

<dt>0<dd>Successful completion of the listing.

<dt>&gt;0<dd>An error occurred.

</dl>
<p>
Otherwise, the exit status will be that of the commands executed by
<i>fc</i>.
</blockquote><h4><a name = "tag_001_014_676">&nbsp;</a>CONSEQUENCES OF ERRORS</h4><blockquote>
Default.
</blockquote><h4><a name = "tag_001_014_677">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
Since editors sometimes use file descriptors
as integral parts of their editing,
redirecting their file descriptors as part of the
<i>fc</i>
command can produce unexpected results.
For example, if
<i><a href="vi.html">vi</a></i>
is the
<i>FCEDIT</i>
editor, the command:
<pre>
<code>
fc -s | more
</code>
</pre>
will not work correctly on many systems.
<p>
Users on windowing systems may want to have separate
history files for each window by setting
<i>HISTFILE</i>
as follows:
<pre>
<code>
HISTFILE=$HOME/.sh_hist$$
</code>
</pre>
</blockquote><h4><a name = "tag_001_014_678">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_679">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
The IEEE PASC 1003.2 Interpretations Committee has forwarded concerns about 
parts of this interface definition to the IEEE PASC Shell and Utilities Working Group
which is identifying the corrections.
A future revision of this specification will align with
IEEE Std. 1003.2b when finalised.
</blockquote><h4><a name = "tag_001_014_680">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="sh.html">sh</a></i>.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>
